<?php

namespace app\api\controller;

use app\api\model\Category as CategoryModel;
use app\api\model\WxappCategory as WxappCategoryModel;

/**
 * 商品分类控制器
 * Class Goods
 * @package app\api\controller
 */
class Category extends Controller
{
    /**
     * 分类页面
     * @return array
     * @throws \think\exception\DbException
     */
    public function index()
    {
        // 分类模板
        $templet = WxappCategoryModel::detail();
        // 商品分类列表
        $list = array_values(CategoryModel::getCacheTree());
        return $this->renderSuccess(compact('templet', 'list'));
    }

    public function catelist()
    {
        $list = CategoryModel::getCacheTree();
        print_r($list);die();
        $new = [];
        foreach($list as &$val){
            $bool = false;
            if(!empty($val)){
                $bool = true;
            }
            $val['ishaveChild'] = $bool;
            $new[] = $val;
        }

        return $this->renderSuccess($new);
    }
}
